import libtorrent as lt
from MediaCenter.DownTools.HttpDown import HttpDown
from MediaCenter.DownTools.TorrentClient import TorrentClient
import MediaCenter.DownTools.tmp as tmp
import subprocess
from subprocess import Popen, PIPE

import asyncio
import time
import sys




#ses = lt.session({'listen_interfaces': '0.0.0.0:6881'})
HttpDownClient = HttpDown('http://hdhome.org/download.php?id=243721&downhash=9b293386x1748745866x130742x243721xa6cf8a79606116451f0262a754ae8d07')
HttpDownClient.set_cookies({
    'c_secure_uid':'MTMwNzQy',
    'c_secure_pass':'c978e8371e0d01bd1feee8400e1a9ebe',
    'c_secure_ssl':'bm9wZQ%3D%3D',
    'c_secure_tracker_ssl':'bm9wZQ%3D%3D',
    'c_secure_login':'bm9wZQ%3D%3D',
})
torrent_source = HttpDownClient.get_requests()
#print(torrent_source)

Client = TorrentClient(torrent_source,'./bt/')
Client.prepare_download()
file_list = Client.get_file_list()
#print(file_list)

def main():
    tmp.get_ip_addresses()
    # cmd = f"ping baidu.com -n 4"# 拼接ping命令字符串
    # process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    # print(process)
    down2()

def down1():
    Client.select_files([0])
    #print(file_list)
    Client.set_download_range(0, 350, 1024)
    Client.begin_download()

def down2():
    Client.select_files([0])
    # print(file_list)
    # Client.set_download_range(0, 350, 1024)
    Client.begin_download()

main()
# print(file_list)
